package com.ruoyi.web.controller.tool;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.zzw.TEmphasisPeople;
import com.ruoyi.common.core.domain.zzw.TEventManage;
import com.ruoyi.common.core.domain.zzw.TRegionInfo;
import com.ruoyi.common.utils.ChineseNationalityCodeUtil;
import com.ruoyi.common.utils.ChineseUtil;
import com.ruoyi.system.service.ITEmphasisPeopleService;
import com.ruoyi.system.service.ITEventManageService;
import com.ruoyi.system.service.ITRegionInfoService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @Description
 * @Author azoveh
 * @Date $ $
 **/


@RestController
@RequestMapping("/screen/test/people")
public class PeopleDataController {

    @Autowired
    private ITEmphasisPeopleService emphasisPeopleService;
    @Autowired
    private ITRegionInfoService regionInfoService;


    Random random = new Random();
    List<TRegionInfo> regionInfoList = new ArrayList<>();


    @GetMapping("/addPeople")
    public AjaxResult addPeople() {
        for (int i = 0; i < 100; i++) {
            TRegionInfo region = getRegion();
            String name = ChineseUtil.randomChineseName();
            int age = random.nextInt(32) + 18;
            String nation = ChineseNationalityCodeUtil.getNationalityName(random.nextInt(56));

            TEmphasisPeople people = new TEmphasisPeople();
            people.setcPeopleName(name);
            people.setcPeopleSex((long) random.nextInt(2) + 1);
            people.setcRegister(region.getCRegionName());
            people.setcNation(nation);
            people.setcPeopleAge((long) age);
            people.setcMarry((long) random.nextInt(2));
            people.setcAddress(region.getCRegionName());
            people.setcPhone(getPhoneNo());
            people.setcPeopleType((long) random.nextInt(3) + 1);
            people.setcDisposeStatus((long) random.nextInt(3) + 1);
            people.setcWorkStatus((long) random.nextInt(4) + 1);
            people.setcWarningLevel((long) random.nextInt(3) + 1);
            people.setcLowTag(getLowTag());
            people.setcMediumTag(getMediumTag());
            people.setcHightTag(getHighTag());

//            System.out.println(people);

            emphasisPeopleService.insertTEmphasisPeople(people);
        }
        return AjaxResult.success();

    }


    private String getLowTag() {
        List<String> low = Arrays.asList("失业", "低收入", "离婚");
        int index = random.nextInt(low.size());
        return low.get(index);
    }

    private String getMediumTag() {
        List<String> medium = Arrays.asList("房屋拆迁", "补偿款没谈拢", "市民热线投诉");
        int index = random.nextInt(medium.size());
        return medium.get(index);
    }

    private String getHighTag() {
        List<String> high = Arrays.asList("扬言报复社会", "房屋强拆", "信访投诉未果", "醉酒驾驶", "滥用药物或酒精", "强烈抵赖", "情绪激动", "扬言杀人", "暴力行为（攻击，伤害他人）", "自杀，自伤（自残）");
        int index = random.nextInt(high.size());
        return high.get(index);
    }

    private TRegionInfo getRegion() {
        if (CollectionUtils.isEmpty(regionInfoList)) {
            regionInfoList = regionInfoService.list();
        }
        int index = random.nextInt(regionInfoList.size());
        return regionInfoList.get(index);
    }

    private String getPhoneNo() {
        String[] start = {"130", "131", "132", "133", "134", "150", "151", "155", "158", "166", "180", "181", "184", "185", "188"};
        return start[(int) (Math.random() * start.length)] + (10000000 + (int) (Math.random() * (99999999 - 10000000 + 1)));
    }

}
